package util;

import java.util.ArrayList;
import java.util.List;

import util.MapBlock.Position;

import domain.Map;

public class MapRenderer {

	private Map map;

	public MapRenderer(Map map) {
		super();
		this.map = map;
	}

	public List<MapBlock> getBlocks() {

		List<MapBlock> blocks = new ArrayList<MapBlock>();

		int blockIndex = 1;
		for (int i = 1; i <= this.map.mapSize; i++) {
			for (int j = 1; j <= this.map.mapSize; j++) {

				blocks.add(createBlock(i, j, blockIndex++));
			}
		}
		
		return blocks;

	}

	private MapBlock createBlock(int i, int j, int blockIndex) {

		boolean top = false;
		boolean bottom = false;
		boolean left = false;
		boolean right = false;

		// get horizontal position
		if(i == 1)
			top = true;
		else if(i == map.mapSize)
			bottom = true;
		
		if(j == 1)
			left = true;
		else if(j == map.mapSize)
			right = true;
				
		Position pos = Position.INNER;
		
		if(top){
			if(left)
				pos = Position.TOP_LEFT;
			else if(right)
				pos = Position.TOP_RIGHT;
			else pos = Position.TOP;
			
		} else if(bottom){
			
			if(left)
				pos = Position.BOTTOM_LEFT;
			else if(right)
				pos = Position.BOTTOM_RIGHT;
			else pos = Position.BOTTOM;
		}
		
		if(!top && !bottom){			
			if(right)
				pos = Position.RIGHT;
			else if(left)
				pos = Position.LEFT;			
		}

		return new MapBlock(pos);

	}

}
